var Data = require("../../utils/data.js");

Page({
  data: {
    city: "成都",
    date: '',
    tomorrow: '',
    dates: 2,
    hotelName: '如家酒店',
    level: '',
    price: 0,
    selectStar: '0',
    selectStarValue: '经济型',
    hotelInfo: [
      {
        title: '腾格里沙漠通湖草原旅游区',
        price: '39',
        decimal: '00',
        imageUrl: '../../static/images/swipper/tooopen_1.jpg',
        directUrl: ''
      },
      {
        title: '腾格里沙漠通湖草原旅游区',
        price: '39',
        decimal: '00',
        imageUrl: '../../static/images/swipper/tooopen_1.jpg',
        directUrl: ''
      }
    ],
  },
  onShow: function () {
    // 页面显示
    var startDate = wx.getStorageSync("startDate");
    var endDate = wx.getStorageSync("endDate");
    console.log("初始时间>>>" + startDate + endDate);

    if (!startDate || startDate == '' || !endDate || endDate == '') {
      //初始化当前时间
      // wx.clearStorageSync();
      startDate = Data.formatDate(new Date(), "yyyy-MM-dd");
      wx.setStorageSync("startDate", startDate);
      var tomorrow1 = new Date();
      tomorrow1.setDate((new Date()).getDate() + 1);
      var tomorrow = Data.formatDate(new Date(tomorrow1), "yyyy-MM-dd");
      endDate = tomorrow;
      wx.setStorageSync("endDate", tomorrow);
      console.log("如果为空，计算后时间>>>" + startDate + endDate);
    }

    var aDate, oDate1, oDate2, iDays
    aDate = endDate.split("-")
    console.log("aDate>>>:length-" + aDate.length + ",0-" + aDate[0] + ",1-" + aDate[1] + ",2-" + aDate[2])
    oDate1 = new Date();
    oDate1.setFullYear(aDate[0]);
    oDate1.setMonth(aDate[1] - 1);
    oDate1.setDate(aDate[2]);

    aDate = startDate.split("-")
    oDate2 = new Date();
    oDate2.setFullYear(aDate[0]);
    oDate2.setMonth(aDate[1] - 1);
    oDate2.setDate(aDate[2]);
    console.log("oDate2》》》", oDate2)
    iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24)    //把相差的毫秒数转换为天数  
    console.log("iDays》》》", iDays);
    this.setData({
      date: startDate,
      tomorrow: endDate,
      dates: iDays
    });
  },
  //事件处理函数
  bindViewTap: function () {
    var that = this;
    var startDate = that.data.date;
    var endDate = that.data.tomorrow;
    wx.navigateTo({
      url: '../calender/index?startDate=' + startDate + "&endDate=" + endDate
    })
  },
  selectCity: function () {
    wx.navigateTo({
      url: ''
    })
  },
  inputHotelName: function (e) {
    this.setData({
      hotelName: e.detail.value
    })
  },
  selectStarLevel: function (e) {
    this.setData({
      selectStar: e.currentTarget.dataset.type,
      selectStarValue: e.currentTarget.dataset.detail
    })
  },
  sliderChange: function (e) {
    this.setData({
      price: (e.detail.value === 600 ? '不限' : e.detail.value)
    })
  },
  complete: function () {
    this.hideModal();
  },
  search: function () {
    
  },
  showModal: function () {
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },
  hideModal: function () {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false
      })
    }.bind(this), 200)
  }
})